jvance.com

.net, c#, asp.net, linq, htpc, woodworking

Jarrett's Tech Blog - For October 2009

  1. Comparison of YUI Compressor for .Net to Microsoft Ajax Minifier

    Minify

    Microsoft just released the Microsoft Ajax Minifier for minifying javascript files.  Since I've been using the Yahoo! UI Library: YUI Compressor for .Net to do this in AtomSite, I thought it would be great to compare the two to see which is best.  I'm mainly interested in the file size reduction but it would be nice to know any speed differences as well.

    The Test

    image

    This method allows me to test compress some javascript using any method I pass into the Func delegate and capture the results.

    To get a reasonable sample of the performance I minified 3 different files with each method 1000 times.  I attempted to configure both algorithms to produce the smallest output possible.

     image

    The Results

    image

    From these results you can see that Microsoft AJAX Minifier creates smaller files in about the same amount of time.  Note, both algorithms have been set in aggressive, or hypercrush, mode to rename variables and perform other tweaks for reducing file size. The Microsoft AJAX Minifier seemed to have more granular options for tweaking output. However, the YUI Compressor is open source so you could add additional options if you need them.

    The Comparison

    Scorecard Speed Size Reduction Options CSS & JS Support Build Task Open Source
    YUI Compressor lose lose lose win win win
    Microsoft AJAX Minifier win win win lose win lose

    And the Winner is..

    It depends.  I suggest using the Microsoft AJAX Minifier as it produces smaller files.  However, the YUI Compressor.Net better satisfies my needs as it can minify both JS and CSS files.  So, when I need to minify dynamic combinations of both types of files, I'll use Yahoo! UI Library: Compressor for .Net.  When I need to do one-time minification during a build or prior to deployment, I'll use the Microsoft AJAX Minifier.

    Download

    I've uploaded the test solution and console app so you can run the tests yourself.

    JsMinTest.zip (291KB) fixed

    More Reads

    Check out how I am using minification and combination in AtomSite to speed up page load time.

    Posted by JarrettV on October 19 at 11:57 PM

© Copyright 2024